﻿/*
 * 由SharpDevelop创建。
 * 用户： xieen
 * 日期: 2013-08-21
 * 时间: 13:27
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using System.Collections;
using System.Collections.Concurrent;

namespace GoF23Learning._14.Command_Pattern.Refactor
{
	/// <summary>
	/// Description of CommandCenter.
	/// </summary>
	public class CommandCenter
	{
		Stack commands = new Stack();
		Stack undoList = new Stack();
		
		public void Excute(){			
			foreach (ICommand command in commands) {
				command.Excute();
			}
		}
		
		public void Undo(){
			var canUndo = true;
			if(canUndo){
				ICommand command =(ICommand) commands.Pop();
			command.Undo();
			
			undoList.Push(command);
			}
			
			
		}
		public void Redo(){
			var canRedo = true;
			if(canRedo){
			ICommand command =(ICommand)  undoList.Pop();
			command.Undo();
			}
		}
		
	}
}
